﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class p_userlogin : System.Web.UI.Page
{
    string n = string.Empty;
    string p = string.Empty;
    protected void Page_Load(object sender, EventArgs e) {
        if (!string.IsNullOrEmpty(Request.Form["n"])) {
            n = Request.Form["n"];
        }
        if (!string.IsNullOrEmpty(Request.Form["p"])) {
            p = Request.Form["p"];
        }
        if (n == "") {
            Response.Write("e3"); Response.End();
        }
        if (p == "") {
            Response.Write("e1"); Response.End();
        }

        string result = "";

        //判断是否为管理员
        if (n == "admin" && p == "admin888") {
            UserCookiesManage.SaveAdminCookies(n, p);
            result = "admin";
            Response.Write(result);
            Response.End();
        }

        //判断帐号是否为培训师
        Exam.Core.Model.Master master = new Exam.Core.DAL.Master().getMasterByName(Server.HtmlEncode(n));
        if (master.MasterID.Trim() != "") {
            if (master.MasterPassword.ToLower().Trim() == p.ToLower().Trim()) {//培训师密码正确
                UserCookiesManage.SaveManageCookies(master);
                result = "teacher";
            }
            else {//密码错误
                result = "pwderr";
            }

        }
        else {//判断帐号是否为考生
            Exam.Core.Model.Student model = new Exam.Core.DAL.Student().StudentByNumber(Server.HtmlEncode(n));
            if (model.StudentID == "") {//用户不存在
                result = "";
            }
            else {
                if (model.StudentPassword.ToLower().Trim() == p.ToLower().Trim()) {//密码正确
                    UserCookiesManage.SaveStudentCookies(model);
                    result = "student";
                }
                else {//密码错误
                    result = "pwderr";
                }
            }

        }

        

        Response.Write(result);
        Response.End();

    }
}